<?php namespace app\home\controller;

use houdunwang\db\Db;
use houdunwang\view\View;

class Common{
    public function __construct()
    {
        //1.获取标题数据
        $WebSetData = $this->getWebSet();
        View::with('WebSetData',$WebSetData);
        //2.分类数据
        $cateData = $this->getCateData();
        //p($cateData);
        View::with('cateData',$cateData);
        //3.获取所有分类数据
        $allCateData = $this->getAllCate();
        //p($allCateData);
        View::with('allCateData',$allCateData);
        //4获取标签云
        $tagData = $this->getTag();
        View::with('tagData',$tagData);
        //5.底部友情链接
        $linkData = $this->getLink();
        //6.底部最新文章


    }
    /**
     * 5.底部友情链接
     */
    public function getLink()
    {
       $a = Db::table('link')->get();
       p($a);
    }
    /**
     * 4.获取标签云
     */
    public function getTag()
    {
        return Db::table('tag')->where('')->get();
    }
    /**
     * 3.右侧分类列表分类数据
     */
    public function getAllCate()
    {
       $data = Db::table('category')->get();
      // p($data);
       foreach($data as $k=>$v)
       {
            $data[$k]['total'] = Db::table('article')->where('category_cid',$v['cid'])->count();

       }
       //p($data);
       return $data;
    }

    /**
     * 2.导航条分类数据
     */
    public function getCateData()
    {
        return Db::table('category')->where('pid',0)->limit(3)->get();
        //p($a);
    }

    //动作
    /**
     * 1.获取配置文件中的数据
     */
    public function getWebSet(){
    //此处书写代码...
        return Db::table('webset')->lists('name,value');
    }
}
